{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "17ec0bbf-adb4-440d-b7ca-bb71f4e0c285",
   "metadata": {},
   "source": [
    "### 显示 OpenVINO 运行时设备，并使用查询设备 API 功能打印它们的指标和默认配置值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "353f062b-78ba-4eb7-b23a-03c224fdedd1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ INFO ] Available devices:\n",
      "[ INFO ] CPU :\n",
      "[ INFO ] \tSUPPORTED_PROPERTIES:\n",
      "[ INFO ] \t\tAVAILABLE_DEVICES: \n",
      "[ INFO ] \t\tRANGE_FOR_ASYNC_INFER_REQUESTS: 1, 1, 1\n",
      "[ INFO ] \t\tRANGE_FOR_STREAMS: 1, 16\n",
      "[ INFO ] \t\tEXECUTION_DEVICES: CPU\n",
      "[ INFO ] \t\tFULL_DEVICE_NAME: Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz\n",
      "[ INFO ] \t\tOPTIMIZATION_CAPABILITIES: FP32, INT8, BIN, EXPORT_IMPORT\n",
      "[ INFO ] \t\tDEVICE_TYPE: Type.INTEGRATED\n",
      "[ INFO ] \t\tDEVICE_ARCHITECTURE: intel64\n",
      "[ INFO ] \t\tNUM_STREAMS: 1\n",
      "[ INFO ] \t\tINFERENCE_NUM_THREADS: 0\n",
      "[ INFO ] \t\tPERF_COUNT: False\n",
      "[ INFO ] \t\tINFERENCE_PRECISION_HINT: <Type: 'float32'>\n",
      "[ INFO ] \t\tPERFORMANCE_HINT: PerformanceMode.LATENCY\n",
      "[ INFO ] \t\tEXECUTION_MODE_HINT: ExecutionMode.PERFORMANCE\n",
      "[ INFO ] \t\tPERFORMANCE_HINT_NUM_REQUESTS: 0\n",
      "[ INFO ] \t\tENABLE_CPU_PINNING: True\n",
      "[ INFO ] \t\tSCHEDULING_CORE_TYPE: SchedulingCoreType.ANY_CORE\n",
      "[ INFO ] \t\tMODEL_DISTRIBUTION_POLICY: set()\n",
      "[ INFO ] \t\tENABLE_HYPER_THREADING: True\n",
      "[ INFO ] \t\tDEVICE_ID: \n",
      "[ INFO ] \t\tCPU_DENORMALS_OPTIMIZATION: False\n",
      "[ INFO ] \t\tLOG_LEVEL: Level.NO\n",
      "[ INFO ] \t\tCPU_SPARSE_WEIGHTS_DECOMPRESSION_RATE: 1.0\n",
      "[ INFO ] \t\tDYNAMIC_QUANTIZATION_GROUP_SIZE: 32\n",
      "[ INFO ] \t\tKV_CACHE_PRECISION: <Type: 'float16'>\n",
      "[ INFO ] \t\tAFFINITY: Affinity.CORE\n",
      "[ INFO ] \n"
     ]
    }
   ],
   "source": [
    "#!/usr/bin/env python3\n",
    "# -*- coding: utf-8 -*-\n",
    "# Copyright (C) 2018-2025 Intel Corporation\n",
    "# SPDX-License-Identifier: Apache-2.0\n",
    "import logging as log\n",
    "import sys\n",
    "\n",
    "import openvino as ov\n",
    "\n",
    "\n",
    "def param_to_string(parameters) -> str:\n",
    "    \"\"\"Convert a list / tuple of parameters returned from OV to a string.\"\"\"\n",
    "    if isinstance(parameters, (list, tuple)):\n",
    "        return ', '.join([str(x) for x in parameters])\n",
    "    else:\n",
    "        return str(parameters)\n",
    "\n",
    "\n",
    "def main():\n",
    "    log.basicConfig(format='[ %(levelname)s ] %(message)s', level=log.INFO, stream=sys.stdout)\n",
    "\n",
    "    # --------------------------- Step 1. Initialize OpenVINO Runtime Core --------------------------------------------\n",
    "    core = ov.Core()\n",
    "\n",
    "    # --------------------------- Step 2. Get metrics of available devices --------------------------------------------\n",
    "    log.info('Available devices:')\n",
    "    for device in core.available_devices:\n",
    "        log.info(f'{device} :')\n",
    "        log.info('\\tSUPPORTED_PROPERTIES:')\n",
    "        for property_key in core.get_property(device, 'SUPPORTED_PROPERTIES'):\n",
    "            if property_key not in ('SUPPORTED_PROPERTIES'):\n",
    "                try:\n",
    "                    property_val = core.get_property(device, property_key)\n",
    "                except TypeError:\n",
    "                    property_val = 'UNSUPPORTED TYPE'\n",
    "                log.info(f'\\t\\t{property_key}: {param_to_string(property_val)}')\n",
    "        log.info('')\n",
    "\n",
    "    # -----------------------------------------------------------------------------------------------------------------\n",
    "    return 0\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    main()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d942703f-3e4e-4d07-b37f-4712c1b2e35c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
